package com.chcit.demoureport.conifg;

import com.bstek.ureport.definition.datasource.BuildinDatasource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;


//@Configuration
public class HaoCaiDataSource implements BuildinDatasource {

    private static final String NAME = "耗材数据源";
    private Logger log = LoggerFactory.getLogger(HaoCaiDataSource.class);



    @ConfigurationProperties(prefix = "oracle.datasource") // application.properteis中对应属性的前缀
    //@Bean
    public DataSource getOracleDataSource() {
       /* DataSourceBuilder dataSourceBuilder = DataSourceBuilder.create();
        dataSourceBuilder.type(com.alibaba.druid.pool.DruidDataSource.class);
        DruidDataSource druidDataSource = (DruidDataSource) dataSourceBuilder.build();
        initDBInfo(druidDataSource);
        return druidDataSource;*/
        return DataSourceBuilder.create().build();
    }

    /**
     * 数据源名称     
     **/
    @Override
    public String name() {
        return NAME;
    }

    /**
     *          * 获取连接
     *         
     **/
    @Override
    public Connection getConnection() {
        try {
            return getOracleDataSource().getConnection();
        } catch (SQLException e) {
            log.error("Ureport 数据源 获取连接失败！");
            e.printStackTrace();
        }
        return null;
    }


}
